This class is meant as an emulation of EZSlider. last mod: 16-apr-07 sciss
For known issues and different behaviour, consult the help files of JSCStaticText, JSCSlider, and JSCNumberBox.
Note: please use the abstraction layer GUI.ezNumber if possible! (see GUI)
JEZSlider is a wrapper class for managing a label and number box.
Instantiation:
JEZSlider.new( <window>, <dimensions>, <label>, <controlSpec>, <action>, <initVal>, <initAction = false>, <labelWidth = 80>, <numberWidth = 80> )
window – the JSCWindow or JSCContainerView containing the views. dimensions – a Point giving the width and height of the bounding box of the views.label – a StringcontrolSpec – the ControlSpec for the value.action – a Function called when the value changes. The function is passed the JEZSlider instance as its argument.initVal – the value to initialize the number box with. If nil, then it uses the controlSpec's default value.initAction – a Boolean indicating whether the action function should be called when setting the initial value.labelWidth – number of pixels width for the label.numberWidth – number of pixels width for the number box.
The contained views can be accessed via the JEZSlider instance variables labelView, sliderView, and numberView.
Another useful instance variable is round, the rounding precision for the number box display. The default value for round is 0.001 (i.e. maximally three decimal digits).
Example:
( // start server s.boot; ) ( // define a synth SynthDef("window-test", { arg note = 36, fc = 1000, rq = 0.25, bal=0, amp=0.4, gate = 1; var x; x = Mix.fill(4, { LFSaw.ar((note + {0.1.rand2}.dup).midicps, 0, 0.02) }); x = RLPF.ar(x, fc, rq).softclip; x = RLPF.ar(x, fc, rq, amp).softclip; x = Balance2.ar(x[0], x[1], bal); x = x * EnvGen.kr(Env.cutoff, gate, doneAction: 2); Out.ar(0, x); }, [0.1, 0.1, 0.1, 0.1, 0.1, 0] ).send(s); ) ( var w, startButton, noteControl, cutoffControl, resonControl; var balanceControl, ampControl; var synth, cmdPeriodFunc; // make the window w = JSCWindow( "another control panel", Rect( 20, 400, 420, 180 ), resizable: false ); w.front; // make window visible and front window. w.view.decorator = FlowLayout(w.view.bounds); //w.view.background = Gradient( Color.rand( 0.0, 1.0 ), Color.rand( 0.0, 1.0 ), [ \h, \v ].choose ); // add a button to start and stop the sound. startButton = JSCButton( w, 75 @ 24 ) .states_([ [ "Start", Color.black, Color.green ], [ "Stop", Color.white, Color.red ] ]) .action_({ arg view; if( view.value == 1, { // start sound synth = Synth( "window-test", [ \note, noteControl.value, \fc, cutoffControl.value, \rq, resonControl.value, \bal, balanceControl.value, \amp, ampControl.value.dbamp ]); }, { // set gate to zero to cause envelope to release synth.release; synth = nil; }); }); // create controls for all parameters w.view.decorator.nextLine; noteControl = JEZSlider( w, 400 @ 24, "Note", ControlSpec( 24, 60, \lin, 1 ), { arg ez; synth.set( \note, ez.value )}, 36 ); w.view.decorator.nextLine; cutoffControl = JEZSlider( w, 400 @ 24, "Cutoff", ControlSpec( 200, 5000, \exp ), { arg ez; synth.set( \fc, ez.value )}, 1000 ); w.view.decorator.nextLine; resonControl = JEZSlider( w, 400 @ 24, "Resonance", ControlSpec( 0.1, 0.7 ), { arg ez; synth.set( \rq, ez.value )}, 0.2 ); w.view.decorator.nextLine; balanceControl = JEZSlider( w, 400 @ 24, "Balance", \bipolar, { arg ez; synth.set( \bal, ez.value )}, 0 ); w.view.decorator.nextLine; ampControl = JEZSlider(w, 400 @ 24, "Amp", ControlSpec( 0.ampdb, 1.ampdb, \db ), { arg ez; synth.set( \amp, ez.value.dbamp )}, -6 ); // set start button to zero upon a cmd-period cmdPeriodFunc = { startButton.value = 0; synth = nil }; CmdPeriod.add( cmdPeriodFunc ); // stop the sound when window closes and remove cmdPeriodFunc. w.onClose = { synth.free; CmdPeriod.remove( cmdPeriodFunc ); }; )